//封装以恶搞存储到本地的方法

// 存需要转换成json
let set = (key, value) => {
    // console.log(key, value)
    // 保证传进去不为空
    if (key && value) {
        try {
            let json = JSON.stringify(value)
            localStorage.setItem(key, json)
            return json
        } catch (e) {
            console.error(e)
        }
    } else {
        console.error("key和value必须传递")
    }
}
// 取需要转换成对象
let get = (key) => {
    let res = localStorage.getItem(key);
    try {
        let result = JSON.parse(res)
        return result
    } catch (e) {
        console.log(e)
        return res
    }

}

let rm=key=>{
    localStorage.removeItem(key)
}
export default {
    set,
    get,
    rm
}